<?PHP
function OpenTPL_function_math( $number, $operator = NULL, $opValue = NULL, $reverse = FALSE ) {
    if( is_null( $operator ) || is_null( $opValue ) ) {
        return $number;
    } else if( is_null( $opValue ) && ! in_array( strtolower( $operator ), array( 'int', 'abs', 'ceil', 'cos', 'exp', 'floor', 'log', 'log10', 'round', 'sin', 'sqrt', 'tan' ) ) ) {
        return $number;
    }
    $math_result = $number;
    if( in_array( $operator, array( '+', '-', '*', '/', '%', '->', '>/', '>%' ) ) && is_numeric( $number ) && is_numeric( $opValue ) ) {
        // 反向计算，原值和计算值位置对调
        if( $reverse ) {
            $math_result = eval( "return $opValue $operator $number;" );
        } else {
            $math_result = eval( "return $number $operator $opValue;" );
        }
    } else if( is_numeric( $number ) ) {
        $math_result = $operator( $number );
    }
    return $math_result;
}
?>